import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
        plugins: [
            vue(),
        ],
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            }
        },
        server: {
            proxy: {
                "/vcard": {
                    target: "https://vcard.shu.edu.cn",
                    //你的需要请求的服务器地址
                    changeOrigin: true, // 允许跨域
                    secure: false,  //忽略安全证书
                    rewrite: (path) => path.replace(/^\/vcard/, ''), // 重写路径把路径变成空字符,
                    headers: {//重点在这里，添加配置项 headers 就可以了
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'Cookie': 'JSESSIONID=BE8D84916E4EF27A922E30C5E05A1590; Hm_lvt_261eb8674e84ceec74062fc4c8417d09=1699328051; Hm_lpvt_261eb8674e84ceec74062fc4c8417d09=1699328063',
                        'Host': 'vcard.shu.edu.cn',
                        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.3 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 wechatdevtools/1.06.2310080 MicroMessenger/8.0.5 Language/zh_CN webview/1699328030937873 webdebugger port/24902 token/fd95a504d9267d90995ac543eb6a6f79'
                    }
                }
            }
        },
    build: {
        chunkSizeWarningLimit:1500,
        rollupOptions: {
            output:{
                manualChunks(id) {
                    if (id.includes('node_modules')) {

                        return id.toString().split('node_modules/')[1].split('/')[0].toString();
                    }
                }
            }
        }
    }
    }
)
